export class Random {

    private readonly Mode: number = Math.pow(2, 31) - 1;

    constructor(private Seed: number) {
        this.Seed = Seed || Date.now();
    }

    Next(lower?: number, upper?: number): number {
        if (this.IsValidNumber(lower) && this.IsValidNumber(upper)) {
            upper = Math.floor(upper) - 1;
            lower = Math.ceil(lower);
            return Math.floor(this.Next() * (upper - lower + 1)) + lower;
        } else if (this.IsValidNumber(lower)) {
            upper = Math.floor(lower) - 1;
            lower = 0;
            return Math.floor(this.Next() * (upper - lower + 1)) + lower;
        } else {
            const x = Math.sin(this.Seed++) * 10000;
            return x - Math.floor(x);
        }
        // this.Seed = (this.Seed * 9301 + 49297) % this.Mode;
        // return Math.floor(this.Seed / this.Mode * Number.MAX_SAFE_INTEGER);
    }

    IsValidNumber(value: number): boolean {
        if (value !== undefined && value !== null && !Number.isNaN(value)) {
            return true;
        }
        return false;
    }

}
